<%--
  Created by IntelliJ IDEA.
  User: Subin
  Date: 2015-06-14
  Time: 19:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title></title>
    <script type="text/javascript">
        function change(btnObj) {
            //向上一级
            var td = btnObj.parentNode;
            //向下找所有input元素中的第2个(i=1)
            var txtObj =
                    td.getElementsByTagName("input")[1];

            var c = parseInt(txtObj.value);
            //如果点"+"?c+1:
            // 如果c==1?1:
            //如果点"-"c-1;
            c = btnObj.value == "+" ? c + 1 :
                    c == 1 ? 1 :
                    c - 1;
            txtObj.value = c;
        }
    </script>
</head>
<body background="images/2.jpg">
<hr>
<h2 align="center">水&nbsp果</h2>
<hr>
<br>
<table border="1" width="500" align="center">
    <tr height="60">
        <td colspan="5" align="center">商品列表</td>
    </tr>
    <tr bgcolor="lightgrey" align="center">
        <td align="center" width="80">名称</td>
        <td align="center">价格(元/斤)</td>
        <td align="center">数量(斤)</td>
        <td align="center" width="100">购买</td>
    </tr>
    <c:forEach items="${list}" var="fruit">
        <form action="shopcar.do">
            <tr align="center">
                <td>${fruit.SP_NAME}</td>
                <td>${fruit.SP_PRICE}</td>
                <td>
                    <input type="button" value="-" onclick="change(this);">
                    <input name="num" value="1" size="3"/>
                    <input type="button" value="+" onclick="change(this);">
                </td>
                <input type="hidden" name="name" value="${fruit.SP_NAME}"/>
                <td>
                    <input type="submit" value="购买"/>
                    <%--<a href="shopcar.do?name=${fruit.SP_NAME}">购买</a>--%>
                </td>
            </tr>
        </form>
    </c:forEach>
</table>
</body>
</html>
